<include file="Common:header" />

<script type="text/javascript" src="__PUBLIC__/uploadify/jquery.uploadify.min.js"></script>
<link type="text/css"  rel="stylesheet" href="__PUBLIC__/uploadify/uploadify.css">
<style type="text/css">
    .uploadify{display:inline-block;}
    .uploadify-button{border:none;border-radius:5px;margin-top:8px;}
    table.add_tab tr td span.uploadify-button-text{color:#FFF;margin:0;}
    #imagefile{max-height: 250px;max-width: 700px;margin-top: 10px;}
</style>
</head>
	<body>
    <div class="crumb_warp">
        <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
        <i class="fa fa-home"></i> <a href="{:U(MODULE_NAME.'/Index/info')}">首页</a> &raquo; 添加幻灯图
    </div>

    <div class="result_wrap">
        <div class="result_title">
            <h3>快捷操作</h3>
        </div>
        <div class="result_content">
            <div class="short_wrap">
                <a href="{:U(MODULE_NAME.'/Slide/add')}"><i class="fa fa-plus"></i>新增幻灯图</a>
                <a href="{:U(MODULE_NAME.'/Slide/index')}"><i class="fa fa-refresh"></i>刷新页面</a>
            </div>
        </div>
    </div>
    <div class="result_wrap">
		<form action="{:U(MODULE_NAME.'/Slide/add')}" method="post" name="myform">
			<table class="add_tab">

				<tr>
					<th class="tdr">幻灯片名称：</th>
					<td><input type="text" name="name" id="name" /></td>
				</tr>
				<tr>
					<th class="tdr">幻灯片URL：</th>
					<td><input type="text" name="url" size="35" /></td>
				</tr>
				<tr>
					<th class="tdr">排序：</th>
					<td><input type="text" name="sort" value="1" /></td>
				</tr>


                <tr>
                    <th>缩略图：</th>
                    <td>
                        <input type="text" size="50" name="imagefile" >
                        <input id="file_upload" name="file_upload" type="file" multiple="true">
                    </td>
                </tr>
                <tr>
                    <th>缩略图预览：</th>
                    <td>
                        <img src="__PUBLIC__/uploadify/nopic.jpg" id="imagefile"/>
                    </td>
                </tr>


                <tr>
                    <th></th>
                    <td>
                        <input type="submit" id="button" value="提交">
                        <input type="button" class="back" onclick="history.go(-1)" value="返回">
                    </td>
                </tr>

			</table>
		</form>
        </div>
	</body>
</html>

<script type="text/javascript">
    var sid = '{:session_id()}';
    $(function() {
        $('#file_upload').uploadify({
            'debug' : false,// 是否开启浏览器调试
            'buttonText' : '缩略图上传',
            'formData'     : {'timestamp' : '<?php echo time();?>','session_id' : sid},
            'swf'      : "__PUBLIC__/uploadify/uploadify.swf",
            'uploader' : "{:U(MODULE_NAME.'/Upload/uploadify')}",
            "onUploadSuccess" : uploadPicture
    /*        'onUploadSuccess' : function(file, data, response) {
                if(response){
                    $('input[name=art_thumb]').val(data);
                    $('#imagefile').attr('src','__ROOT__/Uploads/thumb/'+data);
                }else{
                    alert(response);
                    alert(data.info);
                }
            }*/
        });

        //可以根据自己的要求来做相应处理
        function uploadPicture(file, data){
            var data = $.parseJSON(data);
            if(data.status){
                $('input[name=imagefile]').val(data.info);
                $('#imagefile').attr('src','__ROOT__/Uploads/thumb/'+data.info);
            } else {
                alert(data.info);
            }
        }

        $("#button").click(function() {
            var name = $("#name").val();
            var imagefile = $('input[name=imagefile]').val();
            if(name == ''){
                layer.msg('幻灯片名称不能为空！');
                $("#name").focus();
                return false;
            }
            if(imagefile =='' ){
                layer.msg('请先上传幻灯图！');
                return false;
            }
        });
    });
</script>